import { MallReqUrl } from '@/helpers/constants/api/mall'
import type { HttpResponseData } from '@/types/api'
import type {
  APICreateTaobaoGift,
  APICreateTaobaoGiftReqData,
  APIGetGoodsDetailReqData,
  APIGetGoodsReqData,
  APIGetOrderReqData,
  APIGetRecordReqData,
  APIGoodsDetail,
  APIGoodsListItem,
  APIRecordListItem,
} from '@/types/api/mall'
import request from '@/utils/request'
import { jsonToFormData } from '@/utils/utils'

// 获取商品列表数据
export function getGoodsList(
  params: APIGetGoodsReqData,
): Promise<HttpResponseData<APIGoodsListItem[]>> {
  return request.post(MallReqUrl.GetGoodsList, jsonToFormData(params))
}
// 获取订单列表数据
export function getOrderList(params: APIGetOrderReqData): Promise<HttpResponseData<unknown>> {
  return request.post(MallReqUrl.GetOrderList, jsonToFormData(params))
}
// 获取记录列表数据
export function getRecordList(
  params: APIGetRecordReqData,
): Promise<HttpResponseData<APIRecordListItem[]>> {
  return request.post(MallReqUrl.GetRecordList, jsonToFormData(params))
}
// 获取商品详情
export function getGoodsDetail(
  params: APIGetGoodsDetailReqData,
): Promise<HttpResponseData<APIGoodsDetail>> {
  return request.post(MallReqUrl.getGoodsDetail, jsonToFormData(params))
}
// 创建淘礼金
export function createTaobaoGift(
  params: APICreateTaobaoGiftReqData,
): Promise<HttpResponseData<APICreateTaobaoGift>> {
  return request.post(MallReqUrl.createTaobaoGift, jsonToFormData(params))
}
